package com.turnengine.client.local.action.command.gwt;

import static com.javabi.common.dependency.DependencyFactory.getDependency;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.javabi.codebuilder.generated.gwt.IGeneratedRemoteServiceServlet;
import com.javabi.command.IExecutableCommandResponse;
import com.javabi.command.errorcode.gwt.GwtErrorCodeException;
import com.javabi.command.executor.ICommandExecutorService;
import com.turnengine.client.local.action.bean.IActionCondition;
import com.turnengine.client.local.action.command.AddActionCondition;
import com.turnengine.client.local.action.enums.ActionConditionExecute;
import com.turnengine.client.local.action.enums.ActionConditionMandatory;
import com.turnengine.client.local.action.enums.ActionConditionType;
import com.turnengine.client.local.action.enums.ActionTargetType;

/**
 * The Add Action Condition Servlet.
 */
public class AddActionConditionServlet extends RemoteServiceServlet implements IGeneratedRemoteServiceServlet, AddActionConditionService {

	public IActionCondition addActionCondition(long loginId, int instanceId, int actionId, ActionTargetType targetType, ActionConditionType type, ActionConditionExecute execute, ActionConditionMandatory mandatory, int conditionId, long conditionAmount) throws GwtErrorCodeException {
		AddActionCondition command = new AddActionCondition(loginId, instanceId, actionId, targetType, type, execute, mandatory, conditionId, conditionAmount);
		ICommandExecutorService service = getDependency(ICommandExecutorService.class);
		IExecutableCommandResponse<IActionCondition> response = service.execute(command);
		if (response.hasErrors()) {
			throw new GwtErrorCodeException(response);
		}
		return response.getReturnValue();
	}
}
